package com.mdinic.blogovi.front.page.person;

import org.apache.wicket.RestartResponseException;
import org.apache.wicket.model.Model;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.util.string.StringValue;

import com.mdinic.blogovi.front.common.AbstractBasePage;
import com.mdinic.blogovi.front.page.HomePage;
import com.mdinic.blogovi.model.Person;

/**
 * Class that represents persons list page.
 * 
 * @author mdinic
 */
public class PersonViewPage extends AbstractBasePage {

    private static final long serialVersionUID = 1L;

    /**
     * Constructor.
     */
    public PersonViewPage(PageParameters pageParameters) {
        super(false);

        StringValue idValue = pageParameters.get(URL_PARAM_NAME);
        Long id = idValue.toOptionalLong();
        if (id == null) {
            throw new RestartResponseException(HomePage.class);
        } else {
            add(new PersonViewPanel(PANEL, new Model<Person>(Person.findPerson(id))));
        }

    }
}
